/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package it.unibo.as.SessionBeans;

import it.unibo.as.HeartsLogic.Card;
import it.unibo.as.HeartsLogic.GameLogic;
import it.unibo.as.HeartsLogic.GameState;
import it.unibo.as.HeartsLogic.TableGame;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Johnny
 */
@Stateless
public class GameLogicBean implements GameLogicBeanLocal {
    @EJB
    private TablesGameBean tablesGameBean;

    @Override
    public Boolean playCard(String tableID, String playerID, Card card) {
        TableGame tableGame;
        GameLogic gameLogic;
        tableGame = tablesGameBean.getTableGameFromID(tableID);
        if(tableGame!=null){
            gameLogic = tableGame.getLogic();
            return gameLogic.playCard(playerID, card);
        }

        return null;
    }

    @Override
    public GameState getGameState(String tableID, String playerID) {
        TableGame tableGame;
        GameLogic gameLogic;
        tableGame = tablesGameBean.getTableGameFromID(tableID);
        if(tableGame!=null){
            gameLogic = tableGame.getLogic();
            return gameLogic.getGameState(playerID);
        }

        return null;
    }

    
    public Boolean playerJoinTable(String playerID, String tableID) {
        TableGame tableGame;
        tableGame = tablesGameBean.getTableGameFromID(tableID);
        if(tableGame != null){
            return tableGame.addPlayer(playerID);
        }
        

        return false;
    }



    // "Insert Code > Add Business Method")
 
}
